package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.view.ViewGroup;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessConsultDynamic;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.entity.ConsultDynamicDetailVO;
import com.digitalchina.lxnsy.entity.ConsultDynamicListVO;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.viewholder.ConsultDynamicDetailHolder;
import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2018/2/7 16:35
 * 修改备注：
 * ================================================
 */
public class ConsultDynamicDetailActivity extends BaseActivity{


    @Bind(R.id.recycler_view)
    EasyRecyclerView recyclerView;
    @Bind(R.id.tv_issue)
    TextView tvIssue;

    private RecyclerArrayAdapter adapter;

    private List<ConsultDynamicListVO.QuestionReplyInfoModels> consultDynamicDetailVOS = new ArrayList<>();
    private ConsultDynamicListVO vo;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_consult_dynamic_detail);
        setTitle("咨询详情");
    }

    @Override
    public void initMember() {

        vo = (ConsultDynamicListVO) getIntent().getSerializableExtra("consultDynamicListVO");

        BusinessConsultDynamic.queryDetails(this, vo.getId(), mHandler);

        tvIssue.setText(vo.getContent());

        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        recyclerView.setAdapterWithProgress(adapter = new RecyclerArrayAdapter(this) {
            @Override
            public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
                return new ConsultDynamicDetailHolder(parent);
            }
        });

    }

    @Override
    public void addListener() {

        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
/*                //点击农事服务列表查看农事服务详情
                ConsultDynamicDetailVO vo = (ConsultDynamicDetailVO) adapter.getItem(position);
//                GotoUtil.gotoActivity(ConsultDynamicDetailActivity.this, MessageContentActivity.class, "ConsultDynamicDetailVO", vo);
                GotoUtil.gotoActivity(ConsultDynamicDetailActivity.this, MessageContentActivity.class, "id", vo.getDetailId());*/
            }
        });
    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (recyclerView == null) {
                    return;
                }
                switch (msg.what) {
                    case MSG.MSG_QUERY_CONSULT_DETAILS_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_QUERY_CONSULT_DETAILS_FIELD:
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {
        consultDynamicDetailVOS = FastJsonUtil.getBeanData(object.toString(), ConsultDynamicListVO.class).questionReplyInfoModels;
        adapter.clear();
        adapter.addAll(consultDynamicDetailVOS);
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


}
